﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using AgileZen.Models;

namespace AgileZen.Sample.Controllers
{
    public class TagController : AgileZenController
    {
        #region Tags

        public ActionResult Index(int projectid)
        {
            var tags = AgileZenService.GetTags(projectid);

            return View(tags);
        }


        public ActionResult Details(int id, int projectid)
        {
            var tag = AgileZenService.GetTag(projectid, id);

            return View(tag);
        }

        public ActionResult Stories(int id, int projectid)
        {
            var stories = AgileZenService.GetStories(projectid, id);

            return View(stories);
        }


        public ActionResult Add(int projectid)
        {
            return View();
        }

        [HttpPost]
        public ActionResult Add(int projectid, Tag tag)
        {
            try
            {
                AgileZenService.CreateTag(projectid, ref tag);

                return RedirectToAction("Details", new { id = tag.Id, projectid = projectid });
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /Project/Edit/5

        public ActionResult Edit(int projectid, int id)
        {

            try
            {
                var tag = AgileZenService.GetTag(projectid, id);
                return View(tag);
            }
            catch
            {
                return View();
            }

        }

        //
        // POST: /Project/Edit/5

        [HttpPost]
        public ActionResult Edit(int projectid, int id, Tag tag)
        {
            try
            {
                // TODO: Add update logic here
                AgileZenService.UpdateTag(projectid, ref tag);
                return RedirectToAction("Index", new { projectid = projectid });
            }
            catch
            {
                return View();
            }
        }

        public ActionResult Delete(int projectid, int id)
        {
            try
            {
                AgileZenService.DeleteTag( projectid, id);

                return RedirectToAction("Index", new { projectid = projectid });
            }
            catch
            {
                return View();
            }
        }
        #endregion

    }
}
